<template>
  <div>
    <el-form label-position="right" :model="recruiterForm" :label-width="formLabelWidth" ref="refRecruiterForm" :rules="rules">
      <el-row>
        <el-col :span="11">
          <el-form-item label="企业名称" prop="enterpriseName">
            <el-input v-model="recruiterForm.enterpriseName" placeholder="请选择企业名称" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="用户名" prop="username">
            <el-input v-model="recruiterForm.username" placeholder="请输入用户名" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="11">
          <el-form-item label="姓名" prop="name">
            <el-input v-model="recruiterForm.name" placeholder="请输入姓名" maxlength="64"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="密码" prop="password">
            <el-input v-model="recruiterForm.password" placeholder="请输入密码" maxlength="255"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="11">
          <el-form-item label="联系电话" prop="contactPhone">
            <el-input v-model="recruiterForm.contactPhone" placeholder="请输入联系电话" maxlength="64"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="邮箱" prop="email">
            <el-input v-model="recruiterForm.email" placeholder="请输入邮箱" maxlength="64"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div class="form-button-container">
      <el-button type="primary" @click="onSave">保存</el-button>
    </div>
  </div>
</template>

<script>
import recruiterApi from '@/api/recruiterApi'
export default {
  name: 'RecruiterAddOfHr',
  components: {},
  mixins: [
  ],
  data () {
    return {
      recruiterForm: {
        enterpriseId: '',
        enterpriseName: '',
        username: '',
        name: '',
        password: '',
        contactPhone: '',
        email: ''
      },
      rules: {
        enterpriseName: [
          { required: true, message: '请输入企业名称', trigger: 'blur' }
        ],
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        name: [
          { required: true, message: '请输入姓名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ],
        contactPhone: [
          { required: true, message: '请输入联系电话', trigger: 'blur' }
        ],
        email: [
          { required: true, message: '请输入邮箱', trigger: 'blur' }
        ],
      },
      enterpriseSelectorVisible: false,
    }
  },
  created () {
    recruiterApi.findById(1)
        .then(resp => {
          if (resp && resp.code === 1) {
            this.recruiterForm = resp.data
          } else {
            this.$message.error('获取数据失败')
          }
        })
        .catch(error => {
          console.error('获取数据失败:', error)
        })
  },
  methods: {
    onSave () {
      this.$refs.refRecruiterForm.validate((valid) => {
        if (valid) {
          recruiterApi.save(this.recruiterForm)
              .then((resp) => {
                if (resp && resp.code === 1) {
                  this.$message.success('保存成功')
                } else {
                  this.$message.error('保存失败:' + (resp.msg ? resp.msg : ''))
                }
              })
              .catch(error => {
                console.log(error)
                this.$message.error('保存失败')
              })
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style lang="scss">
</style>